CROSS_COMPILE = arm-hisiv100nptl-linux-

AR		= $(CROSS_COMPILE)ar
AS		= $(CROSS_COMPILE)as
CC		= $(CROSS_COMPILE)gcc
CPP		= $(CROSS_COMPILE)g++
LD		= $(CROSS_COMPILE)ld
NM		= $(CROSS_COMPILE)nm
OBJCOPY	= $(CROSS_COMPILE)objcopy
OBJDUMP	= $(CROSS_COMPILE)objdump
RANLIB	= $(CROSS_COMPILE)ranlib
SIZE	= $(CROSS_COMPILE)size
STRIP	= $(CROSS_COMPILE)strip

TOPDIR=.
C_INCLUDES=
SUBDIRS=
SRCS=
LIBS=
LIB_OBJ=

C_INCLUDES+=-I$(TOPDIR)/inc/

SUBDIRS+=$(TOPDIR)/rf433/
SUBDIRS+=$(TOPDIR)/gsm/
SUBDIRS+=$(TOPDIR)/camera/
SUBDIRS+=$(TOPDIR)/parsexml/
SUBDIRS+=$(TOPDIR)/serial/
SUBDIRS+=$(TOPDIR)/upgrade/
SUBDIRS+=$(TOPDIR)/msgmanage/
SUBDIRS+=$(TOPDIR)/self_check/
SUBDIRS+=$(TOPDIR)/alarm/
SUBDIRS+=$(TOPDIR)/memwatch/

CFLAGS += -lpthread $(C_INCLUDES) $(LDFLAGS)
CFLAGS += -g -rdynamic -Werror 
#CFLAGS += -DMEMWATCH -DMW_PTHREADS

SRCS+=$(wildcard $(TOPDIR)/*.c)
#SRCS+=$(wildcard $(TOPDIR)/rf433/*.c)
#SRCS+=$(wildcard $(TOPDIR)/camera/*.c)
#SRCS+=$(wildcard $(TOPDIR)/serial/*.c)
#SRCS+=$(wildcard $(TOPDIR)/parsexml/*.c)
#SRCS+=$(wildcard $(TOPDIR)/upgrade/*.c)
#SRCS+=$(wildcard $(TOPDIR)/gsm/*.c)

OBJECTS=$(SRCS:.c=.o)
LIB_OBJ+=$(TOPDIR)/rf433m.a
LIB_OBJ+=$(TOPDIR)/gsm.a
LIB_OBJ+=$(TOPDIR)/camera.a
LIB_OBJ+=$(TOPDIR)/parsexml.a
LIB_OBJ+=$(TOPDIR)/serial.a
LIB_OBJ+=$(TOPDIR)/upgrade.a
LIB_OBJ+=$(TOPDIR)/msgmanage.a
LIB_OBJ+=$(TOPDIR)/self_check.a
LIB_OBJ+=$(TOPDIR)/alarm.a
#LIB_OBJ+=$(TOPDIR)/memwatch.a
LIBS+=-L$(TOPDIR)/camera/lib 
LDFLAGS =  -ljnvsdk -lstdc++ -lm -L./parsexml/lib -lxml2

main:subdirs $(OBJECTS)
	$(CC) -o $@  $(OBJECTS) $(LIBS) $(LIB_OBJ) $(CFLAGS)
	./bin/version_add version_no.h
-include $(OBJECTS:.o=.d)
%.d:%.c
	@set -e; rm -f $@; \
		$(CC) -MM $(C_INCLUDES) $(LIB) $(CFLAGS) $< > $@.$$$$; \
		sed 's,\($*\)\.o[ : ]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
		rm -f $@.$$$$

subdirs:
	@for dir in $(SUBDIRS);do make -C $$dir || exit;done
	
.PHONY:clean
clean:
	@-rm main -f *.o *.d *.d.* *.a
	@for dir in $(SUBDIRS);do make -C $$dir clean || exit;done
